<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="/css/elementui/index.css">
    <link rel="stylesheet" href="/css/exam/css/style.css">
    <link rel="stylesheet" href="/iconfont/iconfont.css">
</head>

<body>
    <div id="app">
        <div class="p-30">
            <el-row>
                <span class="icon iconfont icon-arrow_back"></span> 盘点入库
            </el-row><br>
            <span style="font-size:15px;color:#606266">盘点单号:</span>&nbsp;<span>@{{odd_numbers}}</span>
            <template>
                <h3 class="text-center">北宅街道应急物资入库单</h3>
                <el-table :data="allarr" border style="width: 100%">
                    <el-table-column prop="id" label="ID" width="20" v-if="false"> </el-table-column>
                    <el-table-column prop="goods.name" label="类&ensp;&ensp;别" width="">
                    </el-table-column>
                    <el-table-column prop="materia.name" label="物资名称" width="">
                    </el-table-column>
                    <el-table-column prop="check_num" label="数&ensp;&ensp;量" width="80"> </el-table-column>
                    <el-table-column prop="warehouse_materials.unit" label="单&ensp;&ensp;位" width=""> </el-table-column>
                    <el-table-column prop="warehouse_materials.norms" label="规&ensp;&ensp;格" width="">
                    </el-table-column>
                    <el-table-column prop="warehouse_materials.checkcategory_id" label="所属单位" width="">
                        <template slot-scope="scope">
                            <span v-if="scope.row.warehouse_materials.checkcategory_id==item.id"
                                v-for="item in checkcategory" :key="item.id">
                                @{{item.name}}
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="company.comName" label="单位名称" width="">
                    </el-table-column>
                    <el-table-column prop="company.address" label="具体位置" width=""> </el-table-column>
                    <el-table-column prop="check_remark" label="备&ensp;&ensp;注" width=""> </el-table-column>
                </el-table>

                <br>
                <el-row>
                    <el-button type="primary" @click="submitall" v-debounce><a
                            style="display:block;color:#fff;text-decoration:none">确定</a></el-button>
                </el-row>
            </template>
        </div>

    </div>
</body>
<script src="/css/exam/js/vue.js"></script>
<script src="/css/elementui/index.js"></script>
<script src="/css/exam/js/axios.min.js"></script>
<script src="/css/exam/js/common.js"></script>
<script>
const app = new Vue({
    el: '#app',
    data() {
        return {
            id: '',
            odd_numbers: '',
            applicant: '',
            type: 1,
            warehouse_type: 2,
            token: '',
            allarr: [],
            allmaterials: [],
            goods: [],
            materialList: [],
            get_warehouse_type: [],
            checkcategory: [],
            companys: [],
            rules: {
                applicant: [{
                    required: true
                }, ],
            },
        }

    },
    created() {
        this.getUrlKey(),
            this.getone(),
            this.get(),
            this.getdata(),
            this.token = '{{ csrf_token() }}'
    },
    methods: {
        //获取当前浏览器地址url中的id
        getUrlKey() {
            var url = window.location.href; //获取当前url
            var dz_url = url.split('#')[0]; //获取#/之前的字符串                                                       
            var cs = dz_url.split('?')[1]; //获取?之后的参数字符串
            var cs_arr = cs.split('&'); //参数字符串分割为数组
            var cs = {};
            for (var i = 0; i < cs_arr.length; i++) { //遍历数组，拿到json对象
                cs[cs_arr[i].split('=')[0]] = cs_arr[i].split('=')[1]
            }
            this.id = cs.id;
            this.odd_numbers = cs.odd_numbers;
            console.log("this.odd_numbers:" + this.odd_numbers);
            console.log("this.id:" + this.id);
        },
        // 获取下拉列表
        get() {
            axios.post('/admin/warehouseMaterials/referweb')
                .then(res => {
                    if (res.data.code == 200) {
                        this.goods = res.data.data.goods
                        this.materialList = res.data.data.materialList
                        this.get_warehouse_type = res.data.data.get_warehouse_type
                        this.checkcategory = res.data.data.checkcategory
                        this.companys = res.data.data.companys
                        // console.log(this.checkcategory);
                        // console.log(this.companys);
                        // console.log(this.get_warehouse_type);
                        // console.log(this.materialList);
                        // console.log(this.goods);
                    }
                })
        },
        // 回显数据
        getone() {
            axios.get('/admin/check/materials_data?number=' + this.odd_numbers + '&type=1')
                .then(res => {
                    this.allarr = res.data.data
                    var allmaterials = [];
                    for (let i = 0; i < this.allarr.length; i++) {
                        var obj = {};
                        obj.material_id = this.allarr[i].material_id;
                        obj.goods_id = this.allarr[i].goods_id;
                        obj.checkcategory_id = this.allarr[i].checkcategory_id;
                        obj.company_id = this.allarr[i].company_id;
                        obj.number = this.allarr[i].check_num;
                        obj.unit = this.allarr[i].material_id;
                        obj.norms = this.allarr[i].warehouse_materials.unit;
                        obj.remarks = this.allarr[i].warehouse_materials.norms;
                        obj.seat = this.allarr[i].company.address;
                        obj.odd_numbers = this.odd_numbers;
                        obj.img_url = '';
                        this.allmaterials.push(obj);
                    }
                    this.allarr.forEach((item, i) => {
                        console.log(this.allarr[i].goods_id);
                        this.allmaterials[i].goods_id = this.allarr[i].goods_id
                        console.log(this.allmaterials[i].goods_id);
                        // this.allmaterials[i].material_id  =this.allarr[i].material_id
                        // this.allmaterials[i].checkcategory_id  =this.allarr[i].checkcategory_id
                        // this.allmaterials[i].company_id  =this.allarr[i].company_id
                        // this.allmaterials[i].number  =this.allarr[i].check_num
                        // this.allmaterials[i].unit  =this.allarr[i].warehouse_materials.unit
                        // this.allmaterials[i].norms  =this.allarr[i].warehouse_materials.norms
                        // this.allmaterials[i].remarks  =this.allarr[i].check_remark
                        // this.allmaterials[i].seat  =this.allarr[i].company.address
                        // this.allmaterials[i].img_url  = ''
                        // this.allmaterials[i].odd_numbers  = this.odd_numbers	

                    })
                    console.log(this.allarr);
                    console.log(this.allmaterials);
                }).catch(error => {
                    console.log('请求失败：' + error);
                })

        },
        // 确定保存
        submitall(formName) {

            let pagram = {
                id: this.id,
                applicant: this.applicant,
                warehouse_type: this.warehouse_type,
                _token: this.token,
                materials: this.allmaterials
            }
            axios.post('/admin/warehouseMaterials/warehouseMaterialsRefer', pagram)
                .then(res => {
                    if (res.data.code == 200) {
                        this.$message({
                            message: '保存成功',
                            type: 'success'
                        });
                        this.allarr = [],
                            this.applicant = ''
                    } else {
                        this.$message.info("保存失败！")
                    }
                })

        },

        //获取物资列表
        getdata() {
            this.loading = true
            let vm = this
            axios.post('/admin/materialList/list_data')
                .then(response => {
                    vm.materialList = response.data.data.list;
                    vm.loading = false;
                }).catch(error => {
                    console.log('请求失败：' + error);
                    vm.loading = false;
                })
        },
    },
})
</script>
<style>
.el-upload-list--picture-card .el-upload-list__item {
    width: 60px;
    height: 60px;

}

.el-upload--picture-card {
    width: 60px;
    height: 60px;
    line-height: 60px;
}

a {
    color: #409EFF;
    text-decoration: none;
}
</style>

</html>